package cc.mrbird.system.controller;

import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.system.domain.DaliyDTO;
import cc.mrbird.system.domain.ProjectNum;
import cc.mrbird.system.domain.Role;
import cc.mrbird.system.service.ProjectNumService;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 项目代码
 */
@Controller
public class ProjectNumController extends BaseController {
    //日志信息
    private Logger log = LoggerFactory.getLogger(this.getClass());
    /**
     * 项目代号服务接口
     */
    @Autowired
    private ProjectNumService projectNumService;

    @Log("获取项目代号")
    @RequestMapping("projectNum")
    @RequiresPermissions("projectNum:list")
    public String index() {
        return "system/projectNum/projectNum";
    }

    @Log("获取项目代号展示")
    @RequestMapping("projectNum/list")
    @ResponseBody
    public Map<String, Object> projectNum(QueryRequest request, ProjectNum projectNum) {
        return super.selectByPageNumSize(request, () -> projectNumService.findProjectNumPage(projectNum, request));
    }

    @Log("新增项目代号")
    @RequiresPermissions("projectNum:add")
    @RequestMapping("projectNum/add")
    @ResponseBody
    public ResponseBo projectNum(ProjectNum projectNum) {
        try {
            this.projectNumService.addProjectNum(projectNum);
            return ResponseBo.ok("新增项目代号成功！");
        } catch (Exception e) {
            log.error("新增项目代号失败失败", e);
            return ResponseBo.error("新增项目代号失败，请联系网站管理员！");
        }
    }

    @Log("删除代号")
    @RequestMapping("projectNum/delete")
    @ResponseBody
    public ResponseBo deleteProjectNum(String id) {
        try {
            projectNumService.deleteProjectNum(id);
            return ResponseBo.ok("删除代号成功！");
        } catch (Exception e) {
            log.error("删除代号失败", e);
            return ResponseBo.error("删除代号失败，请联系网站管理员！");
        }
    }

    @Log("修改代号")
    @RequestMapping("projectNum/update")
    @ResponseBody
    public ResponseBo updateProjectNum(ProjectNum projectNum) {
        try {
            this.projectNumService.updateProjectNum(projectNum);
            return ResponseBo.ok("修改代号成功！");
        } catch (Exception e) {
            log.error("修改代号失败", e);
            return ResponseBo.error("修改代号失败，请联系网站管理员！");
        }
    }

}
